package com.team.databoard.common;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.team.databoard.exception.BusinessException;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeDeserializers extends JsonDeserializer<Date> {
    public static final SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
    {
        try
        {
            return format.parse(jsonParser.getText());
        }
        catch(Exception e)
        {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
    }
}
